namespace FnSharp.Fundamental.CommandLine.Test

open NUnit.Framework
open FsUnit
open FnSharp.Fundamental.CommandLine

type DefsT1 () =
    let mutable test1 = new System.Collections.Generic.List<int> ()
    let mutable test2 = new System.Collections.Generic.Dictionary<byte, string> ()
    let mutable test3 = 0
    let mutable test4 = false
    let mutable test5 = Some (0)

    member __.Test1
        with get () = test1
         and set vl = test1 <- vl

    member __.Test2
        with get () = test2
         and set vl = test2 <- vl

    member __.Test3
        with get () = test3
         and set vl = test3 <- vl

    member __.Test4
        with get () = test4
         and set vl = test4 <- vl

    member __.Test5
        with get () = test5
         and set vl = test5 <- vl

type DefsR1 = {
    Test1 : System.Collections.Generic.List<int option>
    Test2 : System.Collections.Generic.Dictionary<byte, string>
    Test3 : int option
    Test4 : bool
    Test5 : int option}

[<AutoOpen>]
module internal Helpers =
    let inline roundtrip value args =
        match value with
        | Choice1Of2 (margs) -> 
            let argsText = Arguments.mapToArgs (margs)
            if args <> argsText then failwith "Mismatch!"
        | Choice2Of2 (error,usage) -> failwith (sprintf "%s\r\n%s" error usage)
   
[<TestFixture>] 
type ArgumentTest () =

    [<Test>]
    member test.``mapToClass<DefsT1> "-Test1 [1] -Test2 {1->"2",2->"10"} -Test3 123 -Test4 false -Test5 100"`` () =
        let args = "-Test1 [1] -Test2 {1->\"2\",2->\"10\"} -Test3 123 -Test4 false -Test5 100"
        let value = Arguments.mapToClass<DefsT1> args

        roundtrip value args

    [<Test>]
    member test.``Positive: mapToRecord<DefsR1>: Supply all args, roundtrip`` () =
        let args = "-Test1 [1] -Test2 {1->\"2\",2->\"10\"} -Test3 123 -Test4 true -Test5 100"
        let value = Arguments.mapToRecord<DefsR1> args

        roundtrip value args

    [<Test>]
    member test.``Positive: mapToRecord<DefsR1>: Supply all args, minus -Test3, roundtrip`` () =
        let args = "-Test1 [1] -Test2 {1->\"2\",2->\"10\"} -Test4 true -Test5 100"
        let value = Arguments.mapToRecord<DefsR1> args

        roundtrip value args